import {observable, action, autorun, makeAutoObservable, toJS, makeObservable} from 'mobx'
export class TodolistStore {
    constructor(){
        makeObservable(this)
        autorun(()=>{
            console.log('running');
            console.log(this.todolist[1])
        })
    }

    @observable
    todolist = [{
        id: '001',
        todo: '抽烟',
        isCompleted: false
    },{
        id: '002',
        todo: '喝酒',
        isCompleted: true
    }]

    @action
    checkboxCliclCallback = (id, checked) => {
        console.log(checked);
        console.log(id);
        const dataId = this.todolist.findIndex(todo => todo.id === id)
        this.todolist[dataId] = {
            ...this.todolist[dataId],
            isCompleted: checked
        }

        console.log(toJS(this.todolist))
    }
}